package cn.crm.web.controller.business;

import cn.crm.common.annotation.Log;
import cn.crm.common.core.controller.BaseController;
import cn.crm.common.core.domain.AjaxResult;
import cn.crm.common.core.page.TableDataInfo;
import cn.crm.common.enums.BusinessType;
import cn.crm.system.domain.pojo.dto.ContactsDto;

import cn.crm.system.domain.pojo.dto.VisitingDto;
import cn.crm.system.domain.pojo.vo.VisitingVo;
import cn.crm.system.service.IVisitingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/visiting")
@Api(tags = "业务维护模块模块")
public class VisitingController extends BaseController {


    @Autowired
    private IVisitingService iVisitingService;
//
//    @GetMapping("/list")
//    @ApiOperation("查询维护资料")
//    @Log(title = "联系人管理", businessType = BusinessType.INSERT)
//    @PreAuthorize("@ss.hasPermi('system:visiting:list')")
//    public TableDataInfo Listvisiting(Long  businessId) {
//        log.debug("开始处理查询维护资料的接口");
//        startPage();
//        List<VisitingVo> visitingVos = iVisitingService.selectVisitingsbyBusinessid(businessId);
//        return  getDataTable(visitingVos) ;
//
//    }

    @GetMapping("/query")
    @ApiOperation("查询拜访资料")
    @Log(title = "拜访管理", businessType = BusinessType.INSERT)
    @PreAuthorize("@ss.hasPermi('system:visiting:list')")
    public TableDataInfo SelectListvisiting(VisitingDto visitingDto) {
        log.debug("开始处理查询维护资料的接口");
        startPage();
        List<VisitingVo> visitingVos = iVisitingService.selectVisitings(visitingDto);
        return  getDataTable(visitingVos) ;

    }


    @Log(title = "拜访记录管理", businessType = BusinessType.DELETE)
    @PostMapping("/add")
    @ApiOperation("添加联系人资料")
    @PreAuthorize("@ss.hasPermi('system:visiting:add')")
    public AjaxResult addvisiting(@RequestBody VisitingDto visitingDto){
        log.debug("开始新增拜访记录的接口");
        int i = iVisitingService.insertVisiting(visitingDto);
        if (i<1){
            return AjaxResult.error("添加拜访记录失败");
        }

        return AjaxResult.success("添加拜访记录成功");
    }

    @Log(title = "拜访记录管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    @ApiOperation("删除拜访记录资料")
    @PreAuthorize("@ss.hasPermi('system:visiting:delete')")
    public AjaxResult delete(@PathVariable Long[] id){
        log.debug("开始删除联系人的接口");
        int i = iVisitingService.delVisiting(id);
        if (i< 1){
            return AjaxResult.error("删除拜访记录失败");
        }

        return AjaxResult.success("删除拜访记录成功");
    }

    @Log(title = "拜访记录管理", businessType = BusinessType.UPDATE)
    @PutMapping("/update")
    @ApiOperation("修改拜访记录资料")
    @PreAuthorize("@ss.hasPermi('system:visiting:update')")
    public AjaxResult update( @RequestBody VisitingDto visitingDto){
        log.debug("开始修改联系人资料的接口");
        int i =    iVisitingService.updateContacts(visitingDto);
        if (i < 1){
            return AjaxResult.error("修改拜访记录失败");
        }
        return AjaxResult.success("修改拜访记录资料成功");
    }




}
